/**
 * @param {number[]} candidates
 * @param {number} target
 * @return {number[][]}
 */
var combinationSum = function(candidates, target) { 


      const result=[]
      candidates.sort((a,b)=>(a-b))
      function bracktrack(start,path,sum)
      {
        if(sum===target)
        {
            result.push([...path])
            return  
        }
        for(let i=start;i<candidates.length;i++)
        {
              const num=candidates[i]
              if(sum+num>target) break
              path.push(num)
              bracktrack(i,path,num+sum)
              path.pop()
        }
      }
     bracktrack(0,[],0)
     return result
};      